﻿<?php
class Test{
	
	public function EmailTest($Validation) {
		echo "<h2>Testview Email</h2>";
		$emailtester = array();
		// Om denna GILTIGA adress returnerar FALSE, avbryts testet
		if ($Validation -> ValidateEmailAddress("a@hotmail.se") == FALSE) {
			$emailtester[] = new Exception("->a@hotmail.se<- Did not pass as a valid Electronic Mail Adress");
		}
		if ($Validation -> ValidateEmailAddress("hej_hej@bulle.se") == FALSE) {
			$emailtester[] = new Exception("->hej_hej@bulle.se<- Did not pass as a valid Electronic Mail Adress");
		}
		if ($Validation -> ValidateEmailAddress("1_23@bulle.se") == FALSE) {
			$emailtester[] = new Exception("->1_23@bulle.se<- Did not pass as a valid Electronic Mail Adress");
		}
		if ($Validation -> ValidateEmailAddress("specialtecken.'&!?@bulle.se") == TRUE) {
			$emailtester[] = new Exception("->specialtecken.'&!?@bulle.se<- Did not pass as a valid Electronic Mail Adress");
		}
		if ($Validation -> ValidateEmailAddress("specialtecken<>(){}@bulle.se") == TRUE) {
			$emailtester[] = new Exception("->specialtecken<>(){}@bulle.se<- Did not pass as a valid Electronic Mail Adress");
		}
		if ($Validation -> ValidateEmailAddress("@bulle.se") == TRUE) {
			$emailtester[] = new Exception("->@bulle.se<- Did not pass as a valid Electronic Mail Adress");
		}
		if ($Validation -> ValidateEmailAddress("bulle.se") == TRUE) {
			$emailtester[] = new Exception("->bulle.se<- Did not pass as a valid Electronic Mail Adress");
		}
		if ($Validation -> ValidateEmailAddress("hej@bulle") == TRUE) {
			$emailtester[] = new Exception("->hej@bulle<- Did not pass as a valid Electronic Mail Adress");
		}
		if ($Validation -> ValidateEmailAddress("hej@ä.se") == TRUE) {
			$emailtester[] = new Exception("->hej@ä.se<- Did not pass as a valid Electronic Mail Adress");
		}
		if ($Validation -> ValidateEmailAddress("hello.world@my.domain.se") == FALSE) {
			$emailtester[] = new Exception("->hello.world@my.domain.se<- Did not pass as a valid Electronic Mail Adress");
		}
		return $emailtester;
	}

	public function SocialsecurityTest($Validation) {
		//Använder luhn-algoritmen och if-satser för att kolla personnummers giltighet.
		echo "<h2>Testview Personnummer</h2>";
		$Socialsecuritynr = array ();
		if ($Validation -> SocialIdentityNumber("880921-3054") == FALSE) {
			$Socialsecuritynr[] = new Exception("->880921-3054<- Did not pass as a valid Social Security Number");
		}
		if ($Validation -> SocialIdentityNumber("8809213054") == FALSE) {
			$Socialsecuritynr[] = new Exception("->8809213054<- Did not pass as a valid Social Security Number");
		}
		 if(is_numeric($Validation -> SocialIdentityNumber("880921305411"))) {
			$Socialsecuritynr[] = new Exception("->880921305411<- Did not pass as a valid Social Security Number");
		} 
		if (is_numeric($Validation -> SocialIdentityNumber("12345678910"))) {
			$Socialsecuritynr[] = new Exception("->12345678910<- Did not pass as a valid Social Security Number");
		} 
		if (is_numeric($Validation -> SocialIdentityNumber("åttioåttanollsjutolv"))) {
			$Socialsecuritynr[] = new Exception("->åttioåttanollsjutolv<- Did not pass as a valid Social Security Number");
		} 
		if ($Validation -> SocialIdentityNumber("19880921-3054") == FALSE) {
			$Socialsecuritynr[] = new Exception("->19880921-3054<- Did not pass as a valid Social Security Number");
		} 
		if ($Validation -> SocialIdentityNumber("198809213054") == FALSE) {
			$Socialsecuritynr[] = new Exception("->198809213054<- Did not pass as a valid Social Security Number");
		}
		return $Socialsecuritynr;
	}

	public function DateTest($Validation) {
		echo "<h2>Testview Datum</h2>";
		$datetest = array();
		if ($Validation -> ValidateDate("1999-10-01") == FALSE) {
			$datetest[] = new Exception("->1999-10-01<- Did not pass as a valid Date");
		}
		if ($Validation -> ValidateDate("99-10-01") == FALSE) {
			$datetest[] = new Exception("->99-10-01<- Did not pass as a valid Date");
		}
		if ($Validation -> ValidateDate("991001") == FALSE) {
			$datetest[] = new Exception("->991001<- Did not pass as a valid Date");
		}
		if ($Validation -> ValidateDate("2005-05-01") == FALSE) {
			$datetest[] = new Exception("->2005-05-01<- Did not pass as a valid Date");
		}
		if ($Validation -> ValidateDate("2005-05-80") == TRUE) {
			$datetest[] = new Exception("->2005-05-80<- Did not pass as a valid Date");
		}
		if ($Validation -> ValidateDate("10005-005-80") == TRUE)
		{
			$datetest[] = new Exception("->10005-005-80<- Did not pass as a valid Date");
		}
		if ($Validation -> ValidateDate("1905-00-10") == TRUE)
		{
			$datetest[] = new Exception("->1905-00-10<- Did not pass as a valid Date");
		}
		if ($Validation -> ValidateDate("05-10-2000") == TRUE)
		{
			$datetest[] = new Exception("->05-10-2000<- Did not pass as a valid Date");
		}
		if ($Validation -> ValidateDate("nittonhundraåttisju-10-20") == TRUE)
		{
			$datetest[] = new Exception("->nittonhundraåttisju-10-20<- Did not pass as a valid Date"); // ? Ha kvar och justera eller ta bort!
			/**
			 * Kastar ett validation error som pekar på Validation.php på line 77. Vilket hänvisar till att stäng-inputet är för långt.
			 */ 
		}
		if ($Validation -> ValidateDate("19030517") == FALSE)
		{
			$datetest[] = new Exception("->19030517<- Did not pass as a valid Date");
		}
		return $datetest;
	}

	public function StringTestHTML($Validation) {
		echo "<h2>Test String with HTML</h2>";
		if ($Validation -> StringValidationHTML("<script></script>") == "&ltscript&gt&lt/script&gt") {
			return true;
		} else {
			return false;
		}
	}

	public function StringTestNonHTML($Validation) {
		echo "<h2>Test String No HTML</h2>";
		if ($Validation -> StringValidationNonHTML("<script><h3>asdasdgajghkjsadfhklasdhlfksa</h3></script>") == "asdasdgajghkjsadfhklasdhlfksa") {
			return true;
		} else {
			return false;
		}
	}

	public function PasswordTest($Validation) {
		echo "<h2>Test av Lösenord</h2>";
		$passwtest = array();
		if ($Validation -> PasswordValidation("ettGiltigtl-sen") == FALSE) {
			$passwtest[] = new Exception("->ettGiltigtl-sen<- Did not pass as a valid Password");
		}
		if ($Validation -> PasswordValidation("kort") == TRUE) {
			$passwtest[] = new Exception("->kort<- Did not pass as a valid Password");
		}
		if ($Validation -> PasswordValidation("dethararettalldelesforlangtlosenord") == TRUE) {
			$passwtest[] = new Exception("->dethararettalldelesforlangtlosenord<- Did not pass as a valid Password");	
		} 
		if ($Validation -> PasswordValidation("åresomtax2") == FALSE) {
			$passwtest[] = new Exception("->åresomtax2<- Did not pass as a valid Password");
		} 
		if ($Validation -> PasswordValidation("hej!mamma") == FALSE) {
			$passwtest[] = new Exception("->hej!mamma<- Did not pass as a valid Password");
		} 
		else {
			return $passwtest;
		}
	}

	public function NumberTest($Validation) {
		echo "<h2>Test av nummer</h2>";
		
		$Numbertest = array();
		
		if ($Validation -> NumberValidation(1) == false) {
			$Numbertest[] = new Exception("Numbervalidation failed");
		} 
		if ($Validation -> NumberValidation("2") == false) {
			$Numbertest[] = new Exception("Stringnumner validation failed");
		}
		if ($Validation -> NumberValidation("tre") == true) {
			$Numbertest[] = new Exception("Literal number validation failed");
		} 	
		return $Numbertest;		
	}
}
